import { Application, Context } from 'egg';
const start = (app: Application) => {
  app.passport.verify(async (ctx: Context, user) => {

    const existsUser = await ctx.model.User.findOne({ username: user.username });
    if (existsUser && existsUser.password === user.password) {
      return existsUser;
    }

    return null;
  });

  app.passport.serializeUser(async (_ctx, user) => {
    return user;
  });
  app.passport.deserializeUser(async (_ctx, user) => {
    return user;
  });
};

export default start;
